home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / gs3.53 / type1enc.ps < prev    next >
Text File  |  1996-01-10  |  3KB  |  67 lines

  1. %    Copyright (C) 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % type1enc.ps
  16. % PostScript language versions of the Type 1 encryption/decryption algorithms.
  17.  
  18. % This file is normally not needed with Ghostscript, since Ghostscript
  19. % implements these algorithms in C.  For the specifications, see Chapter 7 of
  20. % "Adobe Type 1 Font Format," ISBN 0-201-57044-0, published by Addison-Wesley.
  21.  
  22. /.type1crypt    % <R> <from> <to> <proc> .type1crypt <R'> <to>
  23.         % (auxiliary procedure)
  24.  { 4 1 roll
  25.    0 2 index length getinterval
  26.    0 1 2 index length 1 sub
  27.     {        % Stack: proc R from to index
  28.       2 index 1 index get            % proc R from to index C/P
  29.       4 index -8 bitshift xor 3 copy put    % proc R from to index P/C
  30.       5 index exec                % proc R from to C
  31.  
  32. %        Compute R' = ((R + C) * 52845 + 22719) mod 65536
  33. %        without exceeding a 31-bit integer magnitude, given that
  34. %        0 <= R <= 65535 and 0 <= C <= 255.
  35.  
  36.       4 -1 roll add
  37.       dup 20077 mul    % 52845 - 32768
  38.       exch 1 and 15 bitshift add    % only care about 16 low-order bits
  39.       22719 add 65535 and 3 1 roll
  40.     }
  41.    for exch pop 3 -1 roll pop
  42.  } bind def
  43.  
  44. % <state> <fromString> <toString> .type1encrypt <newState> <toSubstring>
  45. %    Encrypts fromString according to the algorithm for Adobe
  46. %      Type 1 fonts, writing the result into toString.
  47. %      toString must be at least as long as fromString or a
  48. %      rangecheck error occurs.  state is the initial state of
  49. %      the encryption algorithm (a 16-bit non-negative
  50. %      integer); newState is the new state of the algorithm.
  51.  
  52. /.type1encrypt
  53.  { { exch pop } .type1crypt
  54.  } bind def
  55.  
  56. % <state> <fromString> <toString> .type1decrypt <newState> <toSubstring>
  57. %    Decrypts fromString according to the algorithm for Adobe
  58. %      Type 1 fonts, writing the result into toString.  Other
  59. %      specifications are as for type1encrypt.
  60.  
  61. /.type1decrypt
  62.  { { pop 2 index exch get } .type1crypt
  63.  } bind def
  64.